<template>
  <div class="food-kang-box">
    <page-reload v-show="loadErr" @needReload="emit('toastFather')"></page-reload>
    <template v-if="!loadErr">
      <div class="yuanze-s" v-if="state.dieData.principle">
        <div class="y-title">饮食原则</div>
        <div class="y-desc"  v-html="state.dieData.principle"></div>
      </div>
      <div class="foodCard">
        <div class="title">调理细则</div>
        <tempalte v-if="state.symptom && state.symptom.suitable&&state.symptom.taboo">
          <div class="s-title"><span class="s-icon"></span><span class="s-t">高风险健康问题</span></div>
          <div class="tagDesc" v-html="state.symptom.highRiskDesc"></div>
          <div class="marB16">
            <div class="cardInner">
              <div class="foodImgBox">
                <img src="@/assets/images/report/food1.png" alt="" class="foodIg">
                <div class="poster-desc">
                  <span>高风险</span>
                  <span>健康问题</span>
                </div>
              </div>
              <div class="right">
                <div class="Rli">
                  <span class="nTag gtag">宜吃</span>
                  <span class="desc">{{state.symptom.suitable}}</span>
                </div>
                <div class="Rli">
                  <span class="nTag rtag">忌吃</span>
                  <span class="desc">{{state.symptom.taboo}}</span>
                </div>
              </div>
            </div>
            <div style="padding-top: 5px">
              <p>{{state.symptom.supplement}}</p>
            </div>
          </div>
        </tempalte>
        <template v-if="state.syndrome">
          <div class="s-title"><span class="s-icon"></span><span class="s-t">调理</span></div>
          <div class="tagDesc" v-html="state.syndrome.nurseDesc"></div>
          <div class="cardInner marB16">
            <div class="foodImgBox">
              <img src="../../../assets/images/report/food2.png" alt="" class="foodIg">
              <div class="poster-desc">
                <template v-for="(riskItem, riskIndex) in state.syndrome.syndromeNames">
                  <span  :key="riskIndex" v-if="riskItem">{{riskItem}}</span>
                </template>
              </div>
            </div>
            <div class="right">
              <div class="Rli">
                <span class="nTag gtag">宜吃</span>
                <span class="desc">{{state.syndrome.suitable}}</span>
              </div>
              <div class="Rli">
                <span class="nTag rtag">忌吃</span>
                <span class="desc">{{state.syndrome.taboo}}</span>
              </div>
            </div>
          </div>
        </template>
        <template>
          <div class="s-title"><span class="s-icon"></span><span class="s-t">您的基础营养需求</span></div>
          <div class="cardInner marB16">
            <div class="foodImgBox">
              <img src="../../../assets/images/report/food3.png" alt="" class="foodIg">
              <div class="poster-desc">
                <span>基础营</span>
                <span>养需求</span>
              </div>
            </div>
            <div class="right">
              <div class="Rli" v-for="(item, index) in state.baseNutrition" :key="index">
                <span class="dot"></span>
                <span class="desc">{{item}}</span>
              </div>
            </div>
          </div>
        </template>
      </div>
      <div class="foodCard">
        <div class="title">全日推荐量</div>
        <div class="foodRecom">
          <div class="r-food"  v-for="(item, index) in state.dieData.foodComponent" :key="index">
            <div class="imgBox">
              <img :src="item.img" alt="" class="riseImg">
              <div class="food-mark">{{item.illustrate}}</div>
            </div>
            <div class="b-food"><span class="dot-food"></span>{{item.appetite}}</div>
          </div>
        </div>
      </div>
      <div class="foodCard">
        <div class="title">推荐药膳</div>
        <div class="r-food">
          <div class="imgBox">
            <img :src="state.dieData.medicinal.dishImg" alt="" class="riseImg">
          </div>
          <div class="b-food"><span class="dot-food"></span>{{state.dieData.medicinal.dishName}}</div>
        </div>
      </div>
    </template>
  </div>
</template>

<script lang="ts" setup>
import { ref, onMounted, reactive, watch, toRefs } from 'vue';
import { useRoute } from 'vue-router';
import { Toast } from 'vant';
import {http} from "@/axios/http";
import * as API from "@/axios/api";
import utils from '@/utils/utils.ts';
import PageReload from '@/components/pageReload.vue';

const route = useRoute();
let checkQueryResult = ref(true)
let state = reactive({
  dieData: {
    medicinal: {},
    foodComponent: [],
    principleDetail: {}
  },
  symptom: {},
  syndrome: {},
  baseNutrition: ''
})

let props = defineProps<{
  foodData: any,
  loadErr: boolean
}>()
let emit = defineEmits(['toastFather'])
let { loadErr } = toRefs(props);

watch(() => props.foodData, (newVal, oldVal) => {
  state.dieData  = newVal
  state.symptom = state.dieData.principleDetail?.symptom
  state.syndrome = state.dieData.principleDetail?.syndrome
  let baseNutrition = state.dieData.principleDetail?.baseNutrition
  state.baseNutrition = baseNutrition.split('\n')
})

let getAssetImg = (src) => {
  return new URL(src, import.meta.url).href
}

</script>

<style scoped lang="scss">
.food-kang-box{
  .nTag{
    padding: 2px 3px;
    background: #FFE6D8;
    border-radius: 2px;
    color: #FF7609;
    margin-right: 6px;
  }
  .gtag{
    background-color: #EDFFE0;
    color: #42A868;
  }
  .rtag{
    background-color: #FFE0E0;
    color: #FE1616;
  }
  .yuanze-s{
    background-image: url("../../../assets/images/report/food-kang.png");
  }
  .foodCard{
    .tagDesc{
      margin-top: 5px;
      line-height: 20px;
      span{
        padding: 2px 3px;
        background: #FFE6D8;
        border-radius: 2px;
        color: #FF7609;
        margin-right: 6px;
      }
    }
    .cardInner{
      display: flex;
      margin-top: 5px;
      .foodImgBox{
        position: relative;
        margin-right: 12px;
        width: 84px;
        height: 84px;
        .poster-desc{
          position: absolute;
          width: 80px;
          height: 80px;
          border-radius: 50%;
          top: 50%;
          left: 50%;
          transform: translate(-50%, -50%);
          background-color: rgba(0,0,0,0.4);
          display: flex;
          align-items: center;
          justify-content: center;
          flex-direction: column;
          color: rgba(255, 255, 255);
          font-size: 12px;
          font-weight: 500;
        }
        .foodIg{
          width: 84px;
          height: 84px;
        }
      }
      .right{
        flex: 1;
        .Rli{
          display: flex;
          line-height: 17px;
          margin-bottom: 12px;
          align-items: baseline;
          &:last-child{
            margin-bottom: 0;
          }
          .dot{
            width: 6px;
            height: 6px;
            background: #AFCED9;
            border-radius: 3px;
            margin-right: 6px;
          }
          .desc{
            flex: 1;
          }
        }
      }
    }
    .foodRecom{
      display: flex;
      flex-wrap: wrap;
      justify-content: space-between;
    }
    .r-food{
      width: 162px;
      margin-bottom: 12px;
      font-size: 14px;
      color: #222222;
      .imgBox{
        position: relative;
        width: 162px;
        height: 110px;
        border-radius: 0px 0px 4px 4px;
        .riseImg{
          width: 162px;
          height: 110px;
        }
        .food-mark{
          position: absolute;
          width: 100%;
          height: 28px;
          line-height: 28px;
          background: rgba(0,0,0,0.3);
          border-radius: 0px 0px 4px 4px;
          left: 0;
          bottom: 0;
          text-align: center;
          color: #ffffff;
        }
      }
      .b-food{
        margin-top: 4px;
        display: flex;
        align-items: center;
        .dot-food{
          width: 13px;
          height: 13px;
          background: #E4F0FF;
          position: relative;
          margin-right: 4px;
          transform: rotate(45deg);
          &:before{
            position: absolute;
            content: '';
            width: 5px;
            height: 5px;
            left: 4px;
            top: 4px;
            background-color: #3F8CF7;
          }
        }
      }
    }
  }
}
</style>
